import request from '@/utils/request'
import { ADMIN } from '@/config/baseUrl'

/**
 * 下载模板
 * @returns
 */
export function downloadTemplateFile(treeId) {
  return request({
    url: `${ADMIN}/general-import/downloadTemplateFile`,
    method: 'get',
    responseType: "arraybuffer",
    params: {
      treeId
    }
  })
}

/**
 * 预检测
 * @param {*} treeId 
 * @returns 
 */
export function preDetection(treeId, file) {
  return request({
    url: `${ADMIN}/general-import/preDetection`,
    method: 'post',
    data: {
      treeId,
      file
    }
  })
}

/**
 * 导入数据库
 * @param {*} treeId 
 * @returns 
 */
export function importToDatabase(treeId) {
  return request({
    url: `${ADMIN}/general-import/importFile`,
    method: 'get',
    params: {
      treeId
    }
  })
}

/**
 * 获取预检测错误列表
 * @param {*} treeId 
 * @returns 
 */
export function getErrorInfos(treeId, current, size) {
  return request({
    url: `${ADMIN}/general-import/getErrorInfoList`,
    method: 'post',
    params: {
      treeId
    },
    data: {
      current,
      size
    }
  })
}

/**
 * 轮询获取导入状态
 * @param {*} treeId 
 * @returns 
 */
export function getImportingInfo(treeId) {
  return request({
    url: `${ADMIN}/general-import/getTemplateTableInfo`,
    method: 'get',
    params: {
      treeId
    }
  })
}

/**
 * 导入错误信息
 * @param {*} treeId 
 * @returns 
 */
 export function exportErrorInfos(treeId) {
  return request({
    url: `${ADMIN}/general-import/exportErrorList`,
    method: 'get',
    responseType: "arraybuffer",
    params: {
      treeId
    }
  })
}
